<%@ include file="/en/jsp/static.jsp" %>
<%@ page import="java.util.*,linuxbox.util.StringUtil,linuxbox.calendar.logic.*,linuxbox.calendar.bean.*,linuxbox.admin.logic.*" %>
<%@ taglib uri="/linuxbox/common.tld" prefix="common" %>
<%@ taglib uri="/linuxbox/Calendar.tld" prefix="Calendar" %>

<%
  BoxCalendar BoxCalHome = BoxCalendar.getInstance();

  Calendar currentDate = (Calendar)session.getAttribute("calendar.CurDate");
  if ( currentDate == null)
  {
    currentDate = Calendar.getInstance(sec.getTimeZone());
    session.setAttribute("calendar.CurDate",currentDate);
  }

  int curCalUserID = curID;
  String tmpStr = (String)session.getAttribute("calendar.CurCalUserID");
  if ( tmpStr == null)
  {
    session.setAttribute("calendar.CurCalUserID", String.valueOf(curCalUserID));
  }
  else
    curCalUserID = Integer.parseInt(tmpStr);

  String VIEW_FORMAT = (String)session.getAttribute("calendar.VIEW_FORMAT");
  //get view format parameter, v=day/week/month/year/search
  if ( VIEW_FORMAT == null )
  {
    VIEW_FORMAT = sec.getConfigString("calendar", "General", "Default View");
    session.setAttribute("calendar.VIEW_FORMAT", VIEW_FORMAT);
  }

//the global objects
  Calendar today = Calendar.getInstance(sec.getTimeZone());
  int timeInterval = sec.getConfigInt("calendar", "General", "Time Interval");
  int workStartHour = sec.getConfigInt("calendar", "General", "Working Hour Start");
  int workEndHour = sec.getConfigInt("calendar", "General", "Working Hour End");
  UserManager um = UserManager.getInstance();

%>

<jsp:include page="/en/jsp/header.jsp" flush="true"/>

<script Language="JavaScript">
  function confirmDel(entry)
  {
    return confirm("Are you sure to delete " + entry);
  }

  function onChangeUser()
  {
    document.changeUserForm.submit();
  }
</script>


<table width="100%" height=26 align=middle border=0 cellpadding=0 cellspacing=0 bgcolor="#f4f4f4" style="font-size:16px;color:#d05000">
  <tr>
    <td nowrap="nowrap">	  &nbsp;<img src="<%=BoxStatic.imageDir%>itemball.jpg" width=14 height=15 border=0 align="absmiddle">
      <b><%=boxName%> - <%=um.getUserDisplayName(curCalUserID, um.USERNAME_FORMAT_ALL)%>'s Calendar</b>
    </td>
		<form method="post"  name="changeUserForm" action="<%=BoxStatic.servletDir%>BoxCalendarAction">
  	<td align=right nowrap="nowrap"   valign="middle">

<%
  if (curCalUserID == curID)
  {
%>
    	<a href="<%=BoxStatic.servletDir%>BoxCalendarAction?SubmitEdit=new">Add Event</a> |
<%
	}
%>

    	<a href="<%=BoxStatic.servletDir%>BoxCalendarAction?u=<%=curID%>">My Calendar</a> |
      <a href="<%=BoxStatic.servletDir%>BoxCalendarSettingsAction?SubmitEdit=edit">
        Settings
      </a> |
    	    View
      	  <select name="u" size="1" onchange="onChangeUser()">
<%
            int[] userids = um.getAllUsers(" order by lastname, firstname");
            if (userids != null && userids.length >0)
            {
              for (int i = 0; i < userids.length; i++)
              {
                out.print("<option value=\"");
                out.print(userids[i]);
                out.print("\"");
                if (curCalUserID == userids[i])
                {
                  out.print(" selected ");
                }
                out.print(">");
                out.print(um.getUserDisplayName(userids[i], um.USERNAME_FORMAT_ALL));
                out.print("</option>");
              }
            }
%>
        </select>
    </td>
		</form>
  </tr>
</table>

<hr width="100%" color=#E06000 align=left>

<table width="100%" border=0 cellpadding=1 cellspacing=0>
  <tr bgcolor="#dcdcdc">
    <td colspan="2">
      <table cellpadding="3" cellspacing="0" border="1" width="100%">
        <tr>
            <td BGCOLOR="#<%
              if (VIEW_FORMAT.compareTo("day") == 0)
                out.print("7EC1F3");
              else
                out.print("f4f4f4");
              %>" ALIGN="middle">&nbsp;<font face="Arial,Helvetica" size="-1"
              COLOR="black"><a href="<%=BoxStatic.servletDir%>BoxCalendarAction?v=day&t=<%=currentDate.getTime().getTime()%>">Day</a></font>&nbsp;
            </td>
            <td BGCOLOR="#<%
              if (VIEW_FORMAT.compareTo("week") == 0)
                out.print("7EC1F3");
              else
                out.print("f4f4f4");
              %>" ALIGN="middle">&nbsp;<font color="blue" SIZE="-1"
              face="Arial,Helvetica"><a href="<%=BoxStatic.servletDir%>BoxCalendarAction?v=week&t=<%=currentDate.getTime().getTime()%>">Week</a></font>&nbsp;
            </td>
            <td BGCOLOR="#<%
              if (VIEW_FORMAT.compareTo("month") == 0)
                out.print("7EC1F3");
              else
                out.print("f4f4f4");
              %>" ALIGN="middle">&nbsp;<font color="blue" SIZE="-1"
              face="Arial,Helvetica"><a href="<%=BoxStatic.servletDir%>BoxCalendarAction?v=month&t=<%=currentDate.getTime().getTime()%>">Month</a></font>&nbsp;
            </td>
            <td BGCOLOR="#<%
              if (VIEW_FORMAT.compareTo("year") == 0)
                out.print("7EC1F3");
              else
                out.print("f4f4f4");
              %>" ALIGN="middle">&nbsp;<font color="blue" SIZE="-1"
              face="Arial,Helvetica"><a href="<%=BoxStatic.servletDir%>BoxCalendarAction?v=year&t=<%=currentDate.getTime().getTime()%>">Year</a></font>&nbsp;
            </td>
            <td BGCOLOR="#<%
              if (VIEW_FORMAT.compareTo("list") == 0)
                out.print("7EC1F3");
              else
                out.print("f4f4f4");
              %>" ALIGN="middle">&nbsp;<font color="blue" SIZE="-1"
              face="Arial,Helvetica"><a href="<%=BoxStatic.servletDir%>BoxCalendarAction?v=list">Event List</a></font>&nbsp;
            </td>
            <td BGCOLOR="#<%
              if (VIEW_FORMAT.compareTo("search") == 0)
                out.print("7EC1F3");
              else
                out.print("f4f4f4");
              %>" ALIGN="middle">&nbsp;<font color="blue" SIZE="-1"
              face="Arial,Helvetica"><a href="<%=BoxStatic.servletDir%>BoxCalendarAction?v=search">Search</a></font>&nbsp;
            </td>
        </tr>
      </table>
    </td>
  </tr>
<tr>

<td valign=top width="1%">
  <table BORDER="0" WIDTH="100%" CELLPADDING="0" ALIGN="left">
    <tr>
      <td WIDTH="1%" VALIGN="top">
        <table CELLPADDING="0" CELLSPACING="0" BORDER="1" WIDTH="100%">
  <%
    if (VIEW_FORMAT.compareTo("year") == 0)
    {%>
      <%@include file="BoxYearPicker.jsp" %>
  <% }
    else if (VIEW_FORMAT.compareTo("month") == 0)
    {%>
      <%@include file="BoxMonthPicker.jsp" %>
  <% } else
    { %>
      <%@include file="BoxDayPicker.jsp" %>
  <% } %>

          <tr>
            <td NOWRAP COLSPAN="4" ALIGN="middle" BGCOLOR="#ffffcc"><font size="-1"><b><a
              href="<%=BoxStatic.servletDir%>BoxCalendarAction?v=day&t=<%=today.getTime().getTime()%>">Today</a></b> &nbsp;is
            	<%=StringUtil.getDateTimeFormatString(sec.getTimeZone(), BoxStatic.LONG_DATE_FORMAT, today.getTime())%>
              </font>
            </td>
          </tr>
        </table>
      </td>
    </tr>
    <tr>
      <td WIDTH="1%" VALIGN="top"><p align="center">
  <!-- SpaceID=152200017 loc=W noad --><!-- west tips here -->    </td>
    </tr>
<%
  if (curCalUserID == curID)
  {
%>
    <tr>
      <td width="1%" valign="top">
        <form method="post" name="QuickAdd" action="<%=BoxStatic.servletDir%>BoxCalendarAction">
          <table cellpadding="2" cellspacing="0" border="0" width="100%">
            <tr>
              <td bgcolor="#7EC1F3" align="left"><font size="-1" face="Arial,Helvetica"><b>Quick Add</b></font></td>
            </tr>
            <tr>
              <td bgcolor="#eeeeee">
                <font face="Arial,Helvetica" size="1"><b>Event Subject</b></font><br>
                <input name="SUBJECT" maxlength="80" size="18"><br>
                <font face="Arial,Helvetica" size="1"><b>Date &amp; Time</b><br>
                <select name="FROM_MONTH" size="1">
                  <common:MonthList selected="<%=currentDate.get(Calendar.MONTH)%>" allownull="false" shortformat="true" />
                </select>
                <select name="FROM_DAY" size="1">
                  <common:DayList selected="<%=currentDate.get(Calendar.DAY_OF_MONTH)%>" allownull="false" />
                </select>
                <input type="hidden" name="DURATION_MINUTE" value="30"/>
                <select name="FROM_HOUR" size="1">
                  <common:HourList selected="<%=currentDate.get(Calendar.HOUR_OF_DAY)%>" allownull="false" />
                </select>
                <select name="FROM_MINUTE" size="1">
                  <common:MinuteList timeinterval="<%=timeInterval%>" selected="<%=currentDate.get(Calendar.MINUTE)%>" allownull="false" />
                </select> <br>
               <input type="submit" name="SubmitSave" value="Add"> </font>
              </td>
            </tr>
          </table>
        </form>
      </td>
    </tr>
<%
}
if (VIEW_FORMAT.compareTo("search") != 0)
{
%>
    <tr>
      <td width="1%" valign="top">
        <form method="post" name="QuickSearch" action="<%=BoxStatic.servletDir%>BoxCalendarAction">
        <input type="hidden" name="v" value="search">
        <input type="hidden" name="SEARCH_BY_TITLE" value="1">
        <table cellpadding="3" cellspacing="0" border="0" width="100%">
          <tr>
            <td bgcolor="#7EC1F3" align="left"><font size="-1" face="Arial,Helvetica">
              <b>Search Event Titles</b></font>
            </td>
          </tr>
          <tr>
            <td bgcolor="#eeeeee"><input name="SEARCH_WORDS" maxlength="80" size="14">
            <font face="Arial,Helvetica" size="1"><input type="submit" name="SubmitSearch" value="Find">&nbsp;
            </font>&nbsp;&nbsp; </td>
          </tr>
          <tr>
            <td bgcolor="#eeeeee">
              <a href="<%=BoxStatic.servletDir%>BoxCalendarAction?v=search">Advanced Search</a>
            </td>
          </tr>
        </table>
        </form>
      </td>
    </tr>
<%
}
%>
	</table>
</td>

<td valign=top align=left>

<% if (VIEW_FORMAT.compareTo("search") == 0)
  { %>
    <%@include file="BoxCalendarSearch.jsp" %>
<%}
  else if (VIEW_FORMAT.compareTo("list") == 0)
  { %>
    <%@include file="BoxCalendarEventList.jsp" %>
<%}
  else if (VIEW_FORMAT.compareTo("year") == 0)
  { %>
    <%@include file="BoxCalendarYear.jsp" %>
<%}
  else if (VIEW_FORMAT.compareTo("week") == 0)
  { %>
    <%@include file="BoxCalendarWeek.jsp" %>
<%}
  else if (VIEW_FORMAT.compareTo("month") == 0)
  { %>
    <%@include file="BoxCalendarMonth.jsp" %>
<%}
  else
  { %>
    <%@include file="BoxCalendarDay.jsp" %>
<%}
  %>

</td></tr>
</table>

<hr width="100%" color=#E06000 align=left>

<jsp:include page="/en/jsp/footer.jsp" flush="true"/>
